<?php

/**
 * Mesure form.
 *
 * @package    appcemhti
 * @subpackage form
 * @author     Steve Cancès
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class MesureForm extends BaseMesureForm
{
    public function configure()
    {
        unset
        (
                $this['id_traitement'],
                $this['created_at'],
                $this['updated_at']
        );
        
        $this->widgetSchema['id_echantillon'] = new sfWidgetFormInputHidden();
        
        $this->widgetSchema['id_methode_mesure']->setLabel("Méthode de mesure");
        $q = Doctrine_Core::getTable('Lieu')->getLieu();
        $this->setWidget('id_lieu', new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Lieu'), 'add_empty' => true, 'query' => $q)));
        $this->widgetSchema['id_lieu']->setLabel("Lieu");
        $this->widgetSchema['ok'] = new sfWidgetFormSelectRadio(array(
            'choices' => (array(
                1 => "Oui",
                0 => "Non"
            ))
        ));
        $this->defaults['ok'] = 1;
        $this->widgetSchema['date_mesure']->setLabel("Date");
        $this->widgetSchema['fichiernt']->setLabel("Fichier ou dossier (Données non traitées)");
        $this->defaults['fichiernt'] = "file://///";
        $this->widgetSchema['fichiert']->setLabel("Fichier ou dossier (Données traitées)");
        $this->defaults['fichiert'] = "file://///";
        
        
        $dateWidget = new sfWidgetFormI18nDate(array(
            'format' => '%day%/%month%/%year%',
            'month_format' => 'short_name',
            'culture' => 'fr'
        ));
        $this->widgetSchema['date_mesure'] = new sfWidgetFormJQueryDate(array(
             'config' => '{altField: "#label_choix_date", altFormat: "D, dd MM, yy"}',
            'image'  => '/images/calendar_icon3.png',
            'culture'=> 'fr',
            'date_widget' => $dateWidget
        ));
        $this->widgetSchema['date_mesure']->setLabel("Date du traitement");
        $this->widgetSchema['date_mesure']->setAttribute("style", "display: none;");

        $this->validatorSchema['date_mesure']->setMessage('invalid', 'Date non valide.');
        
        $this->widgetSchema['date_mesure_label'] = new sfWidgetFormInputText();
        $this->widgetSchema['date_mesure_label']->setLabel(" ");
        $this->widgetSchema['date_mesure_label']->setAttribute("disabled", "disabled");
        $this->widgetSchema['date_mesure_label']->setAttribute("id", "label_choix_date");
        
        $this->widgetSchema->moveField('id_lieu', sfWidgetFormSchema::AFTER, 'id_methode_mesure');
        $this->widgetSchema->moveField('date_mesure_label', sfWidgetFormSchema::AFTER, 'date_mesure');
        
        $this->validatorSchema['id_methode_mesure']->setMessage('required', 'Champ obligatoire.');
    }
}
